home *** CD-ROM | disk | FTP | other *** search
/ Hottest 6 / Hottest 6 (1996)(PDSoft)[!].iso / software / fredfish / 1050.lha / Programs / Binary_dt / source / classbase.c < prev    next >
C/C++ Source or Header  |  1994-11-30  |  3KB  |  129 lines

  1. /*
  2. ** $PROJECT: binary.datatype
  3. **
  4. ** $VER: classbase.c 39.2 (30.11.94)
  5. **
  6. ** by
  7. **
  8. ** Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
  9. **
  10. ** (C) Copyright 1994
  11. ** All Rights Reserved !
  12. **
  13. ** $HISTORY:
  14. **
  15. ** 30.11.94 : 039.002 : SuperClassBase removed
  16. ** 14.11.94 : 039.001 :  initial
  17. */
  18.  
  19. #include "classbase.h"
  20.  
  21. LibCall Class *ObtainBinaryEngine (REGA6 struct ClassBase *cb)
  22. {
  23.    return(cb->cb_Class);
  24. }
  25.  
  26. LibCall struct Library *LibInit (REGD0 struct ClassBase *cb, REGA0 BPTR seglist, REGA6 struct Library * sysbase)
  27. {
  28.    cb->cb_SegList = seglist;
  29.    cb->cb_SysBase = sysbase;
  30.    InitSemaphore (&cb->cb_Lock);
  31.  
  32.    if(cb->cb_SysBase->lib_Version >= 39)
  33.    {
  34.       cb->cb_IntuitionBase = OpenLibrary ("intuition.library",39);
  35.       cb->cb_GfxBase       = OpenLibrary ("graphics.library", 39);
  36.       cb->cb_DOSBase       = OpenLibrary ("dos.library",      39);
  37.       cb->cb_UtilityBase   = OpenLibrary ("utility.library",  39);
  38.    } else
  39.       cb = NULL;
  40.  
  41.   return((struct Library *) cb);
  42. }
  43.  
  44. LibCall LONG LibOpen (REGA6 struct ClassBase *cb)
  45. {
  46.    LONG retval = (LONG) cb;
  47.  
  48.    ObtainSemaphore (&cb->cb_Lock);
  49.  
  50.    /* Use an internal use counter */
  51.    cb->cb_Lib.lib_OpenCnt++;
  52.    cb->cb_Lib.lib_Flags &= ~LIBF_DELEXP;
  53.  
  54.    if (cb->cb_Lib.lib_OpenCnt == 1)
  55.    {
  56.       retval = (LONG) NULL;
  57.       if(cb->cb_Class == NULL)
  58.          if((cb->cb_IFFParseBase = OpenLibrary ("iffparse.library", 39)))
  59.             if((cb->cb_DataTypesBase = OpenLibrary ("datatypes.library", 39)))
  60.                if((cb->cb_Class = initClass(cb)))
  61.                   retval = (LONG) cb;
  62.  
  63.       if(!retval)
  64.       {
  65.          if(cb->cb_IFFParseBase)
  66.          {
  67.             CloseLibrary(cb->cb_IFFParseBase);
  68.             cb->cb_IFFParseBase = NULL;
  69.          }
  70.  
  71.          if(cb->cb_DataTypesBase)
  72.          {
  73.             CloseLibrary(cb->cb_DataTypesBase);
  74.             cb->cb_DataTypesBase = NULL;
  75.          }
  76.  
  77.          cb->cb_Lib.lib_OpenCnt--;
  78.       }
  79.    }
  80.    ReleaseSemaphore (&cb->cb_Lock);
  81.  
  82.    return (retval);
  83. }
  84.  
  85. LibCall LONG LibClose (REGA6 struct ClassBase *cb)
  86. {
  87.    LONG retval = NULL;
  88.  
  89.    ObtainSemaphore (&cb->cb_Lock);
  90.  
  91.    if (cb->cb_Lib.lib_OpenCnt)
  92.       cb->cb_Lib.lib_OpenCnt--;
  93.  
  94.    if((cb->cb_Lib.lib_OpenCnt == 0) && cb->cb_Class)
  95.    {
  96.       if(FreeClass (cb->cb_Class))
  97.       {
  98.          cb->cb_Class = NULL;
  99.          CloseLibrary(cb->cb_DataTypesBase);
  100.          CloseLibrary(cb->cb_IFFParseBase);
  101.       } else
  102.          cb->cb_Lib.lib_Flags |= LIBF_DELEXP;
  103.    }
  104.  
  105.    if(cb->cb_Lib.lib_Flags & LIBF_DELEXP)
  106.        retval = LibExpunge (cb);
  107.  
  108.    ReleaseSemaphore (&cb->cb_Lock);
  109.  
  110.    return (retval);
  111. }
  112.  
  113. LibCall LONG LibExpunge(REGA6 struct ClassBase *cb)
  114. {
  115.    BPTR seg = cb->cb_SegList;
  116.  
  117.    Remove((struct Node *) cb);
  118.  
  119.    CloseLibrary(cb->cb_UtilityBase);
  120.    CloseLibrary(cb->cb_DOSBase);
  121.    CloseLibrary(cb->cb_GfxBase);
  122.    CloseLibrary(cb->cb_IntuitionBase);
  123.  
  124.    FreeMem((APTR)((ULONG)(cb) - (ULONG)(cb->cb_Lib.lib_NegSize)), cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
  125.  
  126.    return((LONG) seg);
  127. }
  128.  
  129.